
use std::slice;

// below fn will error on the second slice.
// fn split_at_mut(slice: &mut [i32], mid: usize) -> (&mut [i32], &mut [i32]) {
//     let len = slice.len();
//     assert!(mid <= len);
//     (&mut slice[..mid], &mut slice[mid..])
// }

fn split_at_mut(slice: &mut [i32], mid: usize) -> (&mut [i32], &mut [i32]) {
    let len = slice.len();
    let ptr = slice.as_mut_ptr();

    assert!(mid <= len);

    unsafe {
        (
            slice::from_raw_parts_mut(ptr, mid),
            slice::from_raw_parts_mut(ptr.add(mid), len - mid),
        )
    }
}

// 
fn main() {
    // println!("Hello, world!");
    let mut v = vec![1,2,3,4,5];
    let r = &mut v[..];

    let (a,b) = split_at_mut(r, 3);

    println!("a is {:?}", a);
    println!("b is {:?}", b);
}
